$(function () {
	var id = getQueryString("id");
	vm.mentorId = getQueryString("mentorId");
	vm.getInfo(id);
	
	$("#time1").mobiscroll().datetime({  
		theme: "android-ics light",  
		lang: "zh",  
		cancelText: null,  
		dateFormat: 'yy-mm-dd', //返回结果格式化为年月格式  
		// wheels:[], 设置此属性可以只显示年月，此处演示，就用下面的onBeforeShow方法,另外也可以用treelist去实现  
		onBeforeShow: function (inst) {
			 // inst.settings.wheels[0].length>2?inst.settings.wheels[0].pop():null; 
		},
		onSelect: function (valueText, int) {
			vm.bsnGoutongzhidao.time1 = valueText + ":00";
		}
	});
		 
	vm.msTime2 = $("#time2").mobiscroll().datetime({  
	        theme: "android-ics light",  
	        lang: "zh",  
	        cancelText: null,  
	        dateFormat: 'yy-mm-dd', //返回结果格式化为年月格式  
	        // wheels:[], 设置此属性可以只显示年月，此处演示，就用下面的onBeforeShow方法,另外也可以用treelist去实现  
	        onBeforeShow: function (inst) {
	        	 // inst.settings.wheels[0].length>2?inst.settings.wheels[0].pop():null; 
	        },
			onSelect: function (valueText, int) {
				vm.bsnGoutongzhidao.time2 = valueText + ":00";
			}
	});
	
	$("#edit-form").validate();
});

var vm = new Vue({
	el:'#mapp',
	data:{
		title: "编辑学生信息",
		mentorId: "",
		bsnGoutongzhidao: {},
		msTime1: {},
		msTime2: {}
	},
	methods: {
		saveOrUpdate: function (event) {
			if (StringUtils.isEmpty(vm.mentorId)) {
				alert("无导师id，不能保存");
				return;
			}
			if(!$("#edit-form").valid()) {
				return;
			}
			if (StringUtils.isEmpty(vm.bsnGoutongzhidao.time1)) {
				alert("请选择开始时间");
				return;
			}
			if (StringUtils.isEmpty(vm.bsnGoutongzhidao.time2)) {
				alert("请结束开始时间");
				return;
			}
			vm.bsnGoutongzhidao.mentorid = vm.mentorId;
			var thisUrl;
			if (StringUtils.isEmpty(vm.bsnGoutongzhidao.id)) {
				thisUrl = ajaxServerUrlG("bsngoutongzhidao/save");
			} else {
				thisUrl = ajaxServerUrlG("bsngoutongzhidao/update");
			}
			$.ajax({
				type: "POST",
			    url: thisUrl,
                contentType: "application/json",
			    data: JSON.stringify(vm.bsnGoutongzhidao),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功');
						if (r.bsnGoutongzhidao) {
							vm.bsnGoutongzhidao = r.bsnGoutongzhidao;
						}
					}else{
						alert(r.msg);
					}
				}
			});
		},
		getInfo: function(id){
			console.log(StringUtils.isEmpty(id));
			
			if (StringUtils.isEmpty(id)) return;
			var thisUrl = ajaxServerUrlG("bsngoutongzhidao/info/" + id);
			$.get(thisUrl, function(r){
					if(r.code === 0){
                		vm.bsnGoutongzhidao = r.bsnGoutongzhidao;
					}else{
						alert(r.msg);
					} 
            });
		},
		gotoSelectStudent: function() {
			if (StringUtils.isEmpty(vm.bsnGoutongzhidao.id) || StringUtils.isEmpty(vm.mentorId)) {
				alert("请先保存!");
				return;
			}
			location.href = "mentorZhiDaoStudentSelect.html?id=" + vm.bsnGoutongzhidao.id + "&mentorId=" + vm.mentorId;
		}
	}
});